package com.shujia.mr.sort;

import com.shujia.mr.wordcount.MyWordCountDriver;
import com.shujia.mr.wordcount.MyWordCountMapper;
import com.shujia.mr.wordcount.MyWordCountReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class SortDriver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        Configuration conf = new Configuration();

        // 一个MapReduce程序就是一个Job
        Job job = Job.getInstance(conf);
        job.setJarByClass(SortDriver.class);
        job.setJobName("sort");

        job.setMapperClass(SortMapper.class);

        // 设置Map阶段输出的Key和Value的数据类型
        job.setMapOutputKeyClass(Score.class);
        job.setMapOutputValueClass(NullWritable.class);

        // 设置最终输出的Key和Value的数据类型
        job.setOutputKeyClass(Score.class);
        job.setOutputValueClass(NullWritable.class);


        // 设置输入输出的路径
        FileInputFormat.addInputPath(job,new Path("output/count"));
        FileOutputFormat.setOutputPath(job,new Path("output/sort"));


        // 提交Job并执行
        job.waitForCompletion(true);
    }
}
